class Solution
{
public:
    int findRepeatDocument(vector<int>& documents)
    {
        unordered_map<int, int> map;
        for (int num : documents)
        {
            map[num]++;
            if (map[num] >= 2)
                return num;
        }
        return documents[documents.size() - 1];
    }
};